package com.ql.controller.cgBingAn;

import com.ql.pojo.keshi.FangShe;
import com.ql.pojo.keshi.Gonneng;
import com.ql.pojo.keshi.JanYan;
import com.ql.pojo.menzhen.Fomulary;
import com.ql.pojo.zydj.Zuyuandengji;
import com.ql.pojo.zyyz.Zuyuanyz;
import com.ql.service.cgBingAn.CgBingAnService;
import com.ql.service.keshi.FangsheService;
import com.ql.service.keshi.GonnengService;
import com.ql.service.keshi.JianyanService;
import com.ql.service.zydj.ZuyuanyzService;
import com.ql.service.zydj.ZydjService;
import com.ql.utils.DateUtils;
import com.ql.utils.PageHelper;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/seeBingAn/")
public class CgBingAnController {
    @Resource
    private CgBingAnService cgBingAnService;
    @Resource
    private FangsheService fangsheService;
    @Resource
    private JianyanService jianyanService;
    @Resource
    private GonnengService gonnengService;
    @Resource
    private ZydjService zydjService;
    @Resource
    private ZuyuanyzService zuyuanyzService;

    /*门诊病案管理*/
    @RequestMapping("bingan")
    public String getBiangAnList(@RequestParam(value = "queryYiName",required = false)String queryYiName,
                                 @RequestParam(value = "queryYiKeShi",required = false)String queryYiKeShi,
                                 @RequestParam(value = "queryYiDate",required = false) String queryYiDate,
                                 @RequestParam(value = "queryDoc",required = false) String queryDoc,
                                 @RequestParam(value = "queryyiQianMing",required = false) String queryyiQianMing,
                                 @RequestParam(value = "queryUid",required = false) String queryUid,
                                 Model model,PageHelper ph,Fomulary fl){
        if (null == queryYiKeShi){
            queryYiKeShi = "0";
        }
        if (null == queryUid || queryUid.equals("")){
            queryUid = "0";
        }
        List<Fomulary> fomularyList = cgBingAnService.getAllFom(ph,queryYiName,Integer.parseInt(queryYiKeShi),null,queryDoc,queryyiQianMing,Integer.parseInt(queryUid));
        model.addAttribute("fomularyList",fomularyList);
        model.addAttribute("currentPageNo",ph.getCurrentPageNo());
        model.addAttribute("totalCount",ph.getTotalCount());
        model.addAttribute("totalPageCount",ph.getTotalPageCount());
        model.addAttribute("queryYiName",queryYiName);
        model.addAttribute("queryYiDate",queryYiDate);
        model.addAttribute("queryDoc",queryDoc);
        model.addAttribute("queryyiQianMing",queryyiQianMing);
        model.addAttribute("queryUid",queryUid);
        return "binanguanliIndex";
    }


    //*查看门诊病案信息*//*
    @RequestMapping("seeBingan")
    public String getSeeBingAn(@RequestParam(value = "id",required = false) int id,
                               @RequestParam(value ="uid",required = false) int uid,
                               @RequestParam(value ="uid",required = false) int uId,
                               @RequestParam(value ="uid",required = false) int UId,
                               Model model){
        Fomulary fomulary = cgBingAnService.getFomById(id);
        FangShe fskByUid = fangsheService.getFSKByUid(uid);
        JanYan jykByUid = jianyanService.getJYKByuid(uId);
        Gonneng gnkByUId = gonnengService.getGNKByUId(UId);

        model.addAttribute("fomulary",fomulary);
        model.addAttribute("fskByUid",fskByUid);
        model.addAttribute("jykByUid",jykByUid);
        model.addAttribute("gnkByUId",gnkByUId);
        return "SeeMzBa";
    }



    /*住院部病案管理*/
    @RequestMapping("zyb")
    public String getZybList(@RequestParam(value = "qryUserId",required = false)String qryUserId,
                             @RequestParam(value = "qryUserName",required = false)String qryUserName,
                             @RequestParam(value = "qryKeshi",required = false)String qryKeshi,
                             @RequestParam(value = "qryDoc",required = false)String qryDoc,
                             @RequestParam(value = "qrycheckInTime",required = false)String qrycheckInTime,
                             PageHelper ph, Model model) throws Exception{
        if (null == qryUserId || qryUserId.equals("")){
            qryUserId = "0";
        }
        if(null == qrycheckInTime || qrycheckInTime.equals( "" )){
            qrycheckInTime = "1971-12-12 12:12:12";
        }
        List<Zuyuandengji> zybaList = cgBingAnService.getAllzhuyuanBa(Integer.parseInt(qryUserId), qryUserName,qryKeshi,qryDoc,DateUtils.parse( qrycheckInTime ),ph);

        model.addAttribute("zybaList", zybaList);
        model.addAttribute("qryUserId", qryUserId);
        model.addAttribute("qryUserName", qryUserName);
        model.addAttribute("qryKeshi", qryKeshi);
        model.addAttribute("qryDoc",qryDoc);
        model.addAttribute("currentPageNo", ph.getCurrentPageNo());
        model.addAttribute("totalCount", ph.getTotalCount());
        model.addAttribute("totalPageCount", ph.getTotalPageCount());
        return "binanguanli";
    }
    /*查看住院部病案详情*/
    @RequestMapping("zybaxq")
    public String getbrxq(@RequestParam("userId") String userId,
                          @RequestParam(value = "currentPageNo",required = false) String currentPageNo, Model model) {
        Zuyuandengji patient = cgBingAnService.getById( Integer.parseInt( userId ));
        if (currentPageNo==null ){
            currentPageNo = "1";
        }
        PageHelper ph = new PageHelper();
        ph.setCurrentPageNo( Integer.parseInt( currentPageNo ));
        List<Zuyuanyz> zuyuanyzs = zuyuanyzService.qryAllYz( Integer.parseInt( userId ), ph );
        model.addAttribute( "patient", patient );
        model.addAttribute( "zuyuanyzs", zuyuanyzs );
        model.addAttribute( "currentPageNo", ph.getCurrentPageNo() );
        model.addAttribute( "totalCount", ph.getTotalCount() );
        model.addAttribute( "totalPageCount", ph.getTotalPageCount() );
        return "SeeZhuYuanBa";
    }
}
